package com.sinog.front.controller.biz;

import com.sinog.core.model.UserDTO;
import com.sinog.core.utilbean.Result;
import com.sinog.front.config.idempotent.Idempotent;
import com.sinog.front.config.log.Log;
import com.sinog.front.feign.biz.ReleaseHelpEduService;
import com.sinog.front.service.user.UserFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @desc 安置帮教管理 - 解除安置帮教管理 - ReleaseHelpEduController
 * @author dangyf
 * @date 2020年2月17日 13点12分
 */
@RestController
public class ReleaseHelpEduController {

    @Resource
    private ReleaseHelpEduService releaseHelpEduService;
    @Autowired
    private UserFacade userService;

    /**
     * 安置帮教管理 - 解除帮教管理 - 列表
     * @param pageIndex 起始
     * @param pageSize 大小
     * @param searchMap 查询条件(审批条件 1:未申请 2:已申请 3:审批通过 4:审批失败)
     * @param sortField 排序字段
     * @param sortOrder 排序方式
     * @return String
     */
    @GetMapping("/azbj/jcbjgl/getReleaseHelpEduList")
    public String getReleaseHelpEduList(
            @RequestParam(required = false, defaultValue = "-1") Integer pageIndex,
            @RequestParam(required = false, defaultValue = "-1") Integer pageSize,
            @RequestParam(required = false) String sortField,
            @RequestParam(required = false) String sortOrder,@RequestParam(required = false) Map<String,Object> searchMap) {
        UserDTO userDTO = userService.getAuthentication();
        searchMap.put("account",userDTO.getAccount());
        searchMap.put("level",userDTO.getLevel());
        searchMap.put("departid",userDTO.getDepartid());
        searchMap.put("orgid",userDTO.getOrgid());
        searchMap.put("sortField",sortField);
        searchMap.put("sortOrder",sortOrder);
        return releaseHelpEduService.getReleaseHelpEduList(searchMap,pageIndex,pageSize);
    }

    /**
     * 安置帮教管理 - 解除帮教管理 - 申请解除帮教
     * @param request request
     * @param data 业务数据
     * @return Result
     */
    @Log(type = "新增", value = "解除安置帮教申请（新增、修改）")
    @Idempotent(paramPos = {1})
    @PostMapping("/azbj/jcbjgl/applyReleaseHelpEdu/save")
    public Result applyReleaseHelpEduSave(HttpServletRequest request,String data) {
        return releaseHelpEduService.save(data);
    }

    /**
     * 安置帮教管理 - 解除帮教管理 - 保存审批解除安置帮教（修改/新增）
     * @param request request
     * @param data 业务数据
     * @return Result
     */
    @Log(type = "新增", value = "解除安置帮教上级审批（新增、修改）")
    @Idempotent(paramPos = {1})
    @PostMapping("/azbj/jcbjgl/auditingReleaseHelpEdu/save")
    public Result auditingReleaseHelpEduSave(HttpServletRequest request,String data) {
        UserDTO userDTO = userService.getAuthentication();
        String loginAccount = userDTO.getAccount();
        return releaseHelpEduService.saveAuditing(data,loginAccount);
    }
}